<?php

namespace app\common\model;

class UserScoreCount extends \think\Model
{
    // 表名
    protected $name = 'user_score_count';

    //获取今天回复次数
    public static function getTodayCount($user_id,$type='quizzes'){
        $user_score_count_info=UserScoreCount::where(['user_id'=>$user_id,'type'=>$type,'date'=>date('Y-m-d')])->find();
        $user_count=0;
        if($user_score_count_info){
            $user_count=$user_score_count_info->count;
        }
        $count=0;
        switch ($type){
            case 'quizzes':
                $count=config('site.answer_number');
                break;
            case 'post':
                $count=config('site.post_number');
                break;
            case 'post_view':
                $count=config('site.post_view_number');
                break;
            default :
                break;
        }
        return $count-$user_count;
    }
    //设置积分次数
    public static function setTodayCount($user_id,$type='quizzes'){
        $user_score_count_info=UserScoreCount::where(['user_id'=>$user_id,'type'=>$type,'date'=>date('Y-m-d')])->find();
        if(!$user_score_count_info){
            UserScoreCount::create(['user_id'=>$user_id,'type'=>$type,'date'=>date('Y-m-d')]);
        }else{
            $user_score_count_info->setInc('count');
        }
    }
}